package com.xxg.fileshand.adapter

import com.blankj.utilcode.util.SPUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.xxg.fileshand.R
import com.xxg.fileshand.app.SetInfo
import com.xxg.fileshand.constant.Constant
import com.xxg.fileshand.greendao.FilesInfoDTO
import com.xxg.fileshand.type.OperateType

class FilesAdapter :
    BaseQuickAdapter<FilesInfoDTO, BaseViewHolder>(R.layout.item_files),
    LoadMoreModule {

    var isFind = false
    var xxx: OperateType? = null

    override fun convert(helper: BaseViewHolder, item: FilesInfoDTO) {
        helper.setText(R.id.tv_name, item.daName ?: "无名")
            .setText(R.id.tv_code, "编号 " + item.daCode)
            .setText(R.id.tv_layer_code, item.caseCodeTrans ?: "层架 未上架")
        if (item.caseCodeTrans.isNullOrEmpty()) {
            helper.setTextColor(R.id.tv_layer_code, context.resources.getColor(R.color._89a1ee))
        } else {
            if (item.caseCodeTrans.startsWith("错架")) {
                helper.setTextColor(R.id.tv_layer_code, context.resources.getColor(R.color.red))
            } else {
                helper.setTextColor(R.id.tv_layer_code, context.resources.getColor(R.color._89a1ee))
            }
        }
        helper.setGone(R.id.bt_find, !isFind)

        if (!SetInfo.isOffline()) {
            if ((xxx == OperateType.OPERATE_TYPE_GUIDE || xxx == OperateType.OPERATE_TYPE_SEARCH)
                && SPUtils.getInstance().getBoolean(Constant.IS_OPEN_JIA)
            ) {
                helper.setGone(R.id.bt_open_jia, false)
                    .setGone(R.id.bt_close_jia, false)
            } else {
                helper.setGone(R.id.bt_open_jia, true)
                    .setGone(R.id.bt_close_jia, true)
            }
        } else {
            helper.setGone(R.id.bt_open_jia, true)
                .setGone(R.id.bt_close_jia, true)
        }

    }

    fun setOperateType(operateType: OperateType?) {
        this.xxx = operateType
    }

}